//
//  WeiboCommentNode.m
//  yuikemall
//
//  Created by yuike5 yuike5 on 12-2-7.
//  Copyright (c) 2012年 yuike. All rights reserved.
//
#import "Comment.h"
#import "WeiboCommentNode.h"

@implementation WeiboCommentNode
@synthesize created_at;
@synthesize text;
@synthesize user;
@synthesize idx;
@synthesize mid;

-(void)dealloc
{
    [created_at release];
    [text release];
    [user release];
    [mid release];
    [super dealloc];
}

-(id) initWithSinaComment:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        self.idx = [[dict valueForKey:@"id"] longLongValue];
        self.mid = [dict valueForKey:@"mid"];
        self.created_at = [dict valueForKey:@"created_at"];
        self.text = [dict valueForKey:@"text"];
        NSDictionary* temp = (NSDictionary*)[dict valueForKey:@"user"];
        self.user = [[[WeiboUserNode alloc] initWithSinaUser:temp] autorelease];
        
        Comment* comment = [Comment commentWithJsonDictionary:dict];
        self.created_at = [NSString stringWithFormat:@"%lld", (long long)comment.createdAt];
    }
    return self;
}


-(id) initWithTencComment:(NSDictionary*)dict
{
    self = [super init];
    if (self) {
        self.idx = [[dict valueForKey:@"id"] longLongValue];
        self.mid = [dict valueForKey:@"id"]; // ???
        self.created_at = [NSString stringWithFormat:@"%lld", [[dict valueForKey:@"timestamp"] longLongValue]];
        self.text = [dict valueForKey:@"text"];

        self.user = [[[WeiboUserNode alloc] initWithTencComment:dict] autorelease];
    }
    return self;
}

-(id) initWithTencCommentCallback:(NSDictionary*)dict  content:(NSString*)content
{
    self = [super init];
    if (self) {
        self.idx = [[dict valueForKey:@"id"] longLongValue];
        self.mid = [dict valueForKey:@"id"]; // ???
        self.created_at = [NSString stringWithFormat:@"%lld", [[dict valueForKey:@"time"] longLongValue]];

        self.text = content;//[dict valueForKey:@"text"]; // XXXXXXXXX no data
        self.user = nil;//[[[WeiboUserNode alloc] initWithTencComment:dict] autorelease]; // XXXXXXXXX no data
    }
    return self;
}

-(NSDate*) nsdate {
    return [NSDate dateWithTimeIntervalSince1970:[self.created_at   doubleValue]];
}

@end
